package com.heima.feigns;

import com.heima.feigns.config.MyFeignAutoConfiguration;
import com.heima.feigns.fallback.WemediaFeignFallback;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.model.wemedia.pojos.WmUser;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;


@Component
@FeignClient(value = "leadnews-wemedia",
        configuration = MyFeignAutoConfiguration.class,
        fallbackFactory = WemediaFeignFallback.class)
public interface WemediaFeign {

    /**
     * feign接口返回值需要加泛型，否则对象会被解析为LinkedHashMap
     * @param user
     * @return
     */
    @PostMapping("/api/v1/user/save")
    ResponseResult<WmUser> save(@RequestBody WmUser user);

    @GetMapping("/api/v1/user/findByName/{name}")
    ResponseResult<WmUser> findByName(@PathVariable("name") String name);

    @GetMapping("/api/v1/news/one/{id}")
    public ResponseResult<WmNews> findWmNewsById(@PathVariable("id") Integer id);
    @PutMapping("/api/v1/news/update")
    ResponseResult updateWmNewsById(@RequestBody WmNews wmNews);
}
